package com.canbot.u05.activity.shoppingGuide.codeMarketing;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.canbot.u05.R;
import com.canbot.u05.activity.BaseActivityNoTitle;
import com.canbot.u05.activity.presidemode.eventbus.AudioEvent;
import com.canbot.u05.utils.ToastTools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CodeTTsSetActivity extends BaseActivityNoTitle {

        @BindView(R.id.code_iv_back)
        Button codeIvBack;

        @BindView(R.id.code_iv_ok)
        Button codeIvOk;

        @BindView(R.id.code_voice_et)
        EditText codeVoiceEt;

        private ToastTools toastTools;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_code_tts_set);
                ButterKnife.bind(this);
                toastTools = ToastTools.newInstance(this);
                initViews();
        }

        private void initViews() {
                Intent intent = getIntent();
                int type = intent.getIntExtra("type", AudioEvent.AUDIO_TYPE_TTS);
                String content = intent.getStringExtra("content");
                if (type == AudioEvent.AUDIO_TYPE_TTS && !TextUtils.isEmpty(content)) {
                        int len = content.length();
                        codeVoiceEt.setText(content);
                        codeVoiceEt.setSelection(len);
                }
        }

        @OnClick({R.id.code_iv_back, R.id.code_iv_ok})
        public void onViewClicked(View view) {
                switch (view.getId()) {
                        case R.id.code_iv_back:
                                finish();
                                break;
                        case R.id.code_iv_ok:
                                //确定
                                String trim = codeVoiceEt.getText().toString().trim();
                                if (TextUtils.isEmpty(trim)) {
                                        toastTools.showText(getString(R.string.enter_text_content));
                                        return;
                                }
                                Intent intent = new Intent();
                                intent.putExtra("type", AudioEvent.AUDIO_TYPE_TTS);
                                intent.putExtra("content", trim);
                                setResult(RESULT_OK, intent);
                                finish();
                                break;
                }
        }
}
